home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / tcl / tests / source.test < prev    next >
Encoding:
Text File  |  1993-11-03  |  3.4 KB  |  103 lines  |  [TEXT/MPS ]

  1. # Commands covered:  source
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/source.test,v 1.8 93/02/17 13:22:56 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. test source-1.1 {source command} {
  32.     set x "old x value"
  33.     set y "old y value"
  34.     set z "old z value"
  35.     set fd [open source.file "w"]
  36.     puts $fd "set x 22"
  37.     puts $fd "set y 33"
  38.     puts $fd "set z 44"
  39.     close $fd
  40.     source source.file
  41.     list $x $y $z
  42. } {22 33 44}
  43. test source-1.2 {source command} {
  44.     set fd [open source.file "w"]
  45.     puts $fd "list result"
  46.     close $fd
  47.     source source.file
  48. } result
  49.  
  50. test source-2.1 {source error conditions} {
  51.     list [catch {source} msg] [string range $msg 0 12]
  52. } {1 {wrong # args:}}
  53.  
  54. test source-2.2 {source error conditions} {
  55.     list [catch {source a b} msg] [string range $msg 0 12]
  56. } {1 {bad argument:}}
  57. test source-2.3 {source error conditions} {
  58.     set fd [open source.file "w"]
  59.     puts $fd "set x 146"
  60.     puts $fd "error \"error in sourced file\""
  61.     puts $fd "set y $x"
  62.     close $fd
  63.     list [catch {source source.file} msg] $msg $errorInfo
  64. } {1 {error in sourced file} {error in sourced file
  65.     while executing
  66. "error "error in sourced file""
  67.     (file "source.file" line 2)
  68.     invoked from within
  69. "source source.file"}}
  70. test source-2.4 {source error conditions} {
  71.     set fd [open source.file "w"]
  72.     puts $fd "break"
  73.     close $fd
  74.     catch {source source.file}
  75. } 3
  76. test source-2.5 {source error conditions} {
  77.     set fd [open source.file "w"]
  78.     puts $fd "continue"
  79.     close $fd
  80.     catch {source source.file}
  81. } 4
  82. test source-2.6 {source error conditions} {
  83.     string tolower [list [catch {source _non_existent_} msg] $msg $errorCode]
  84. } {1 {couldn't read file "_non_existent_": no such file or directory} {posix enoent {no such file or directory}}}
  85.  
  86. test source-3.1 {return in middle of source file} {
  87.     set fd [open source.file "w"]
  88.     puts $fd "set x new-x"
  89.     puts $fd "return allDone"
  90.     puts $fd "set y new-y"
  91.     close $fd
  92.     set x old-x
  93.     set y old-y
  94.     set z [source source.file]
  95.     list $x $y $z
  96. } {new-x old-y allDone}
  97.  
  98. catch {rm source.file}
  99.  
  100. # Generate null final value
  101.  
  102. concat {}
  103.